package com.ruoyi.quartz.task;

import com.ruoyi.system.domain.OrderInfoBO;
import com.ruoyi.system.domain.PropertyFeedback;
import com.ruoyi.system.service.PropertyService;
import com.ruoyi.system.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component("propertyTask")
public class PropertyTask {

    @Autowired
    private TaskService taskService;

    @Autowired
    private PropertyService propertyService;

    public void task(){
        //添加3天前时间
//        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
//        String createTime = dateFormat.format(now);//格式化然后放入字符串中
        Calendar c = Calendar.getInstance();

        c.add(Calendar.DATE, - 3);

        Date time = c.getTime();

        String preDay = dateFormat.format(time);

        String msg ="";


        //3天前未完成订单
        List<OrderInfoBO> orderInfoList = propertyService.getOrderInfoByCreateTime(preDay,3,0);
        if(orderInfoList != null){
            for (OrderInfoBO o: orderInfoList) {
                msg = o.getStoried()+o.getAddress()+"的报修:"+o.getDescribe()+"已经3天未处理，请留意。";
                taskService.send("200014448","wybx",msg);//张勤勇
            }
        }
        //5天前未完成订单
        c = Calendar.getInstance();
        c.add(Calendar.DATE, - 5);
        time = c.getTime();
        preDay = dateFormat.format(time);
        orderInfoList = propertyService.getOrderInfoByCreateTime(preDay,5,0);
        if(orderInfoList != null){
            for (OrderInfoBO o: orderInfoList) {
                PropertyFeedback feedback = propertyService.getFeedbackById(o.getId());
                //设置为已发送
                feedback.setStatus(1);
                propertyService.updateFeedback(feedback);
                msg = o.getStoried()+o.getAddress()+"的报修:"+o.getDescribe()+"已经5天未处理，请留意。第一次反馈为："+feedback.getFirstComment()+"。";
                taskService.send("200003499","wybx",msg);//孙尚红
                taskService.send("200010308","wybx",msg);//查新松
            }
        }
        //7天前未完成订单
        c = Calendar.getInstance();
        c.add(Calendar.DATE, - 7);
        time = c.getTime();
        preDay = dateFormat.format(time);
        orderInfoList = propertyService.getOrderInfoByCreateTime(preDay,7,2);
        if(orderInfoList != null){
            for (OrderInfoBO o: orderInfoList) {
                PropertyFeedback feedback = propertyService.getFeedbackById(o.getId());
                //设置为已发送
                feedback.setStatus(3);
                propertyService.updateFeedback(feedback);
                msg = o.getStoried()+o.getAddress()+"的报修:"+o.getDescribe()+"已经7天未处理，请留意。第一次反馈为："+feedback.getFirstComment()+"。第二次反馈为："+feedback.getSecondComment()+"。";
                taskService.send("200003498","wybx",msg);//周金敏
                taskService.send("200014474","wybx",msg);//闫循龙
                taskService.send("200000004","wybx",msg);//廖春斌
            }
        }

        //8天前未完成订单
        c = Calendar.getInstance();
        c.add(Calendar.DATE, - 8);
        time = c.getTime();
        preDay = dateFormat.format(time);
        orderInfoList = propertyService.getOrderInfoByCreateTime(preDay,8,4);
        if(orderInfoList != null){
            for (OrderInfoBO o: orderInfoList) {
                PropertyFeedback feedback = propertyService.getFeedbackById(o.getId());
                //设置为已发送
                feedback.setStatus(5);
                propertyService.updateFeedback(feedback);
                msg = o.getStoried()+o.getAddress()+"的报修:"+o.getDescribe()+"已经7天未处理，请留意。第一次反馈为："+feedback.getFirstComment()+"。第二次反馈为："+feedback.getSecondComment()+"。第三次反馈为："+feedback.getSecondComment();
                taskService.send("200000031","wybx",msg);//陆浩
                taskService.send("200000004","wybx",msg);//廖春斌
            }
        }

        //10天前未完成订单
        c = Calendar.getInstance();
        c.add(Calendar.DATE, - 10);
        time = c.getTime();
        preDay = dateFormat.format(time);
        orderInfoList = propertyService.getOrderInfoByCreateTime(preDay,10,5);
        if(orderInfoList != null){
            for (OrderInfoBO o: orderInfoList) {
                PropertyFeedback feedback = propertyService.getFeedbackById(o.getId());
                //设置为已发送
                feedback.setStatus(6);
                propertyService.updateFeedback(feedback);
                msg = o.getStoried()+o.getAddress()+"的报修:"+o.getDescribe()+"已经7天未处理，请留意。第一次反馈为："+feedback.getFirstComment()+"。第二次反馈为："+feedback.getSecondComment()+"。第三次反馈为："+feedback.getSecondComment();
                taskService.send("200014475","wybx",msg);
                taskService.send("200000004","wybx",msg);//廖春斌
            }
        }
    }
}
